#include <bits/stdc++.h>
// 2025/04/04
// tag: 
// Author: Forever
// 来去如风，常伴吾身
using namespace std;
using int64 = int64_t;

int t[4], s[1001];
bool dp[1001][1001][4], can[16][4];
string name;

int to_int(char c){
    if (c == 'W')
        return 0;
    if (c == 'I')
        return 1;
    if (c == 'N')
        return 2;
    if (c == 'G')
        return 3;
    return -1;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t[0] >> t[1] >> t[2] >> t[3];
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < t[i]; j++){
            cin >> name;
            can[to_int(name[0]) * 4 + to_int(name[1])][i] = true;
        }
    }
    cin >> name;
    int n = name.size();
    name = " " + name;
    for (int i = 1; i <= n - 1; i++)
        for (int j = 0; j < 4; j++)
            if (can[to_int(name[i]) * 4 + to_int(name[i + 1])][j])
                dp[i][i + 1][j] = true;
    for (int i = 1; i <= n; i++)
        dp[i][i][to_int(name[i])] = true;
    for (int len = 3; len <= n; len++)
        for (int l = 1, r = len; r <= n; l++, r++)
            for (int i = l; i < r; i++)
                for (int j = 0; j < 4; j++)
                    for (int k = 0; k < 4; k++)
                        for (int m = 0; m < 4; m++)
                            if (dp[l][i][j] && dp[i + 1][r][k] && can[j * 4 + k][m])
                                dp[l][r][m] = true;
    bool flag = false;
    if (dp[1][n][0])
        cout << "W", flag = true;
    if (dp[1][n][1])
        cout << "I", flag = true;
    if (dp[1][n][2])
        cout << "N", flag = true;
    if (dp[1][n][3])
        cout << "G", flag = true;
    if (!flag)
        cout << "The name is wrong!" << endl;
    return 0;
}